<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use DB;
class LinkController extends Controller
{
    //显示友情连接模板
    public function link()
    {
		//查询数据
		$link=DB::table('link')->get();
		
		//分配数据
		return view('link.adminLink',['links'=>$link]);
    }
	
	//添加友情链接
	public function addLink(){
		return view('link.addLink');
	}
	
	//添加友情链接操作
	public function insertLink(Request $request){
		//接收表单传递过来的值
		$link=$request->only(['lname','linkurl','lstatus']);
		
		//插入数据
		$result=DB::table('link')->insert($link);
		//判断
		if($result){
			return redirect('/link/adminLink');
		}else{
			return redirect('/link/addLink');
		}
	}
	
	//修改友情链接模板
	public function updateLink($id){
		//查询数据
		$result=DB::table('link')->where('lid','=',$id)->first();
		
		//分配数据
		return view('link.updateLink',['result'=>$result]);
	}
	
	//修改友情链接操作
	public function aupdateLink(Request $request){
		//接收表单传递过来的值
		$result2=$request->only(['lid']);
		$result=$request->only(['lname','linkurl','lstatus']);
		//dd($result);
		$result1=DB::table('link')->where('lid','=',$result2['lid'])->update($result);
		if($result1){
			return redirect('/link/adminLink');
		}else{
			return redirect("/link/updateLink/{$result2['lid']}");
		}
	}
	
	//删除操作
	public function deleteLink($lid){
		//删除商品
		$result=DB::table('link')->where('lid','=',$lid)->delete();
		//返回数据
		if($result){
			return redirect('/link/adminLink');
		}else{
			return redirect('/link/adminLink');
		}
	}
	
	
	
}
